package com.huawei.appmarket.service.appdetail.view.fragment;

import android.os.Build.VERSION;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.FixViewPager;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse.TabInfo;
import com.huawei.appmarket.service.appdetail.view.AppCategoryFragmentProtocol;
import com.huawei.appmarket.service.appdetail.view.AppCategoryFragmentProtocol.Request;
import com.huawei.appmarket.service.appdetail.view.widget.HorizonTabNavigator;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.List;
import o.cin;
import o.ciy;
import o.cjk;
import o.cjm;
import o.cjo;
import o.SomeFragmentStateAdapter;
import o.dre;
import o.drm;
import o.dru;
import o.CollectCheck;
import o.ewm.h;
import o.ewm.j;
import o.FragmentManager;

public class AppCategoryFragment extends TaskFragment<AppCategoryFragmentProtocol> implements com.huawei.appmarket.service.appdetail.view.fragment.AppSubCategoryFragment.b {
    private TabInfo ˊ;
    private String ˋ;
    private drm ˎ;
    private List<TabInfo> ˏ;
    private HorizonTabNavigator ॱ;
    private FixViewPager fixViewP;
    private b ᐝ;

    class b extends SomeFragmentStateAdapter {
        final /* synthetic */ AppCategoryFragment ˎ;
        private Fragment ॱ;

        public b(AppCategoryFragment appCategoryFragment, FragmentManager juVar) {
            this.ˎ = appCategoryFragment;
            super(juVar);
        }

        public CharSequence getPageTitle(int i) {
            TabInfo tabInfo = (TabInfo) this.ˎ.ˏ.get(i);
            if (tabInfo != null) {
                return tabInfo.ᐝ();
            }
            return "";
        }

        public Fragment getItem(int i) {
            Fragment fragment;
            TabInfo tabInfo = (TabInfo) this.ˎ.ˏ.get(i);
            dre ˋ = this.ˎ.ˎ.ˋ(tabInfo.ʼ());
            AppListFragmentRequest appListFragmentRequest = new AppListFragmentRequest();
            appListFragmentRequest.ˋ(tabInfo.ʼ());
            appListFragmentRequest.ˊ(tabInfo.ॱॱ());
            appListFragmentRequest.ॱ(4);
            appListFragmentRequest.ˊ(0);
            if (ˋ == null) {
                appListFragmentRequest.ॱॱ("");
                appListFragmentRequest.ॱ(tabInfo.ͺ() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + tabInfo.ᐝ());
                cjo appListFragmentProtocol = new AppListFragmentProtocol();
                appListFragmentProtocol.ˏ(appListFragmentRequest);
                fragment = (ContractFragment) cjk.ˎ().ˊ(new cjm(((AppCategoryFragmentProtocol) this.ˎ.ˆ()).ˋ(), appListFragmentProtocol));
                if (fragment.ˊ(dru.class) != null) {
                    ((dru) fragment).ˋ(this.ˎ);
                }
            } else {
                appListFragmentRequest.ॱॱ(ˋ.ॱ());
                appListFragmentRequest.ॱ(ˋ.ˋ() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + ˋ.ॱ());
                cjo appListFragmentProtocol2 = new AppListFragmentProtocol();
                appListFragmentProtocol2.ˏ(appListFragmentRequest);
                ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm(((AppCategoryFragmentProtocol) this.ˎ.ˆ()).ˋ(), appListFragmentProtocol2));
                if (contractFragment.ˊ(dru.class) != null) {
                    ((dru) contractFragment).ˋ(this.ˎ);
                }
                if (contractFragment.ˊ(cin.class) != null) {
                    ((cin) contractFragment).ˋ(ˋ.ˏ());
                }
            }
            return fragment;
        }

        public int getCount() {
            int size = this.ˎ.ˏ.size();
            if (size > 4) {
                return 4;
            }
            return size;
        }

        public void setPrimaryItem(ViewGroup viewGroup, int i, Object obj) {
            super.setPrimaryItem(viewGroup, i, obj);
            Fragment fragment = (Fragment) obj;
            if (fragment != this.ॱ) {
                if (fragment instanceof ciy) {
                    ((ciy) fragment).ˋ(i);
                }
                if (this.ॱ instanceof ciy) {
                    ((ciy) this.ॱ).ʽˊ();
                }
                this.ॱ = fragment;
            }
        }
    }

    public void ˏ(Bundle bundle) {
        AppCategoryFragmentProtocol appCategoryFragmentProtocol = (AppCategoryFragmentProtocol) ˆ();
        if (!(appCategoryFragmentProtocol == null || appCategoryFragmentProtocol.ˏ() == null)) {
            Request ˏ = appCategoryFragmentProtocol.ˏ();
            this.ˋ = ˏ.ˋ();
            this.ˏ = ˏ.ˏ();
        }
        if (!(this.ˏ == null || this.ˏ.isEmpty())) {
            ॱˋ(true);
            for (int i = 0; i < this.ˏ.size(); i++) {
                ((TabInfo) this.ˏ.get(i)).ˋ(i);
            }
        }
        if (this.ˎ == null) {
            this.ˎ = new drm(ॱˋ());
            this.ˎ.ˎ(this.ˏ);
        }
        this.ˊ = this.ˎ.ॱ();
        super.ˏ(bundle);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        ViewGroup viewGroup2 = (ViewGroup) layoutInflater.inflate(h.ߴ, viewGroup, false);
        this.fixViewP = (FixViewPager) viewGroup2.findViewById(j.ʼٴ);
        if (this.ˊ != null) {
            FragmentManager ˏॱ = ॱˋ().ˏॱ();
            if (VERSION.SDK_INT > 23) {
                ˏॱ = ʽॱ();
            }
            this.ᐝ = new b(this, ˏॱ);
            this.fixViewP.setAdapter(this.ᐝ);
            if (!CollectCheck.isEmpty(this.ˏ)) {
                this.ॱ = (HorizonTabNavigator) viewGroup2.findViewById(j.ᐝʿ);
                this.ॱ.setViewPager(this.fixViewP);
            }
            this.fixViewP.setCurrentItem(this.ˊ.ˏ());
        }
        ॱˋ().setTitle(this.ˋ);
        return viewGroup2;
    }

    public void ॱ(com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        drm.ˎ(this.ˎ, bVar);
    }
}
